package main

import (
	"code.google.com/p/gorefit"
)

func main() {
	r := gorefit.NewServer("http://www.golang.org/", ":8081", parseGolangOrg)
	r.Serve()
}

func parseGolangOrg(r *gorefit.Server) {
	// Set template file
	r.SetTemplate("template.html")

	// Replace title
	r.Out.Replace("//title", r.In.Get("//title"))
	
	// Replace heading
	r.Out.Replace("//div[@id='heading']", r.In.Get("//div[@id='heading']"))
	
	// Replace menu. Adding the parent from the input page
	r.Out.Replace("//div[@id='menu']", r.In.Get("//div[@id='menu']/.."))
	
	// Replace page
	r.Out.Replace("//div[@id='page']", r.In.Get("//div[@id='page']"))
	
	// Drop all iframes with source from youtube. You could remove the entire video div by removing //div[@id='video']
	r.Out.Remove("//iframe[contains(@src, 'youtube.com')]")
	
	// Instead insert another video in it's place
	r.Out.Append("//div[@id='video']", "<iframe width=\"415\" height=\"241\" src=\"http://www.youtube.com/embed/a1Y73sPHKxw\" frameborder=\"0\" allowfullscreen></iframe>")
	
	// Add debug information
	r.Out.Append("/html/body/div[@id='debug']", r.HTMLMessages(gorefit.DEBUG))

	// Rewrite links
	r.Out.RewriteLinks("http://www.golang.org/", "/")
}

